package aiku.numericalcontroloa.Controller;

import aiku.numericalcontroloa.Base.Utils.HttpStatus;
import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Entity.Role;
import aiku.numericalcontroloa.Service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 黄广庭
 * @Date 2024/1/8 14:20
 */

@RestController
@RequestMapping("/role")
@Slf4j
public class RoleCont {
    private final RoleService roleService;

    public RoleCont(RoleService roleService) {
        this.roleService = roleService;
    }

    /**
     * 添加角色
     * @param role 角色对象
     * @return 结果
     */
    @PostMapping("/addRole")
    public Result addRole(@RequestBody Role role){
        if (role == null){
            return new Result(HttpStatus.BAD_REQUEST,"缺少参数");
        }
        if (roleService.save(role))
            return Result.success("添加成功");
        return Result.error("添加失败");
    }
}
